// pages/orderListDetail/index.js
const app = getApp()
let {
  baseUrl,
  commonUpdate,
  commonUpload
} = app.globalData
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: {},
    baseUrl,
    commonUpdate,
    commonUpload
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(options)

    this.setData({
      dataList: JSON.parse(options.data)
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  dowload() {
    console.log('1111')

    /*  wx.downloadFile({
       url: url, //图片地址
       success: function (res) {
         //wx.saveImageToPhotosAlbum方法：保存图片到系统相册
         wx.saveImageToPhotosAlbum({
           filePath: res.tempFilePath, //图片文件路径
           success: function (data) {

             wx.showModal({
               title: '提示',
               content: '保存成功',
               modalType: false
             })

           },
           // 接口调用失败的回调函数
           fail: function (err) {
             if (err.errMsg === "saveImageToPhotosAlbum:fail:auth denied" || err
               .errMsg === "saveImageToPhotosAlbum:fail auth deny" || err
               .errMsg === "saveImageToPhotosAlbum:fail authorize no response"
             ) {
               wx.showModal({
                 title: '提示',
                 content: '需要您授权保存相册',
                 modalType: false,
                 success: modalSuccess => {
                   wx.openSetting({
                     success(settingdata) {
                       console.log("settingdata",
                         settingdata)
                       if (settingdata
                         .authSetting[
                           'scope.writePhotosAlbum'
                         ]) {
                         wx.showModal({
                           title: '提示',
                           content: '获取权限成功,再次点击图片即可保存',
                           modalType: false,
                         })
                       } else {
                         wx.showModal({
                           title: '提示',
                           content: '获取权限失败，将无法保存到相册哦~',
                           modalType: false,
                         })
                       }
                     },
                     fail(failData) {
                       console.log("failData",
                         failData)
                     },
                     complete(finishData) {
                       console.log("finishData",
                         finishData)
                     }
                   })
                 }
               })
             }
           },
           complete(res) {
             wx.hideLoading(); //隐藏 loading 提示框
           }
         })
       }
     }) */

    let url = "http://192.168.2.10:91/1.pdf"
    wx.downloadFile({
      url: url,
      header: {},
      success: function (res) {
        var filePath = res.tempFilePath;
        wx.shareFileMessage({
          filePath: filePath,
          success() {},
          fail: console.error,
        })
        /*   wx.openDocument({
            filePath: filePath,
            success: function (res) {
              console.log('打开文档成功')
            },
            fail: function (res) {
              console.log(res);
            },
            complete: function (res) {
              console.log(res);
            }
          }) */
      },
      fail: function (res) {
        console.log('文件下载失败');
      },
      complete: function (res) {},
    })
    /*  wx.downloadFile({
       url: "http://192.168.2.10:91/storage/upload/files/doctor/20240830/2024-08-30_1724985202_66d12f7281953.png", //仅为示例，并非真实的资源
       success(res) {
         console.log(res)
         // 只要服务器有响应数据，就会把响应内容写入文件并进入 success 回调，业务需要自行判断是否下载到了想要的内容
         


       },
     }) */
  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})